<template>

  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="95px"
    >
      <el-form-item label="创建日期" prop="searchTime">
        <el-date-picker
          v-model="queryParams.searchTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-200px"
        />
      </el-form-item>

      <el-form-item label="病人姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入病人姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="病人ID" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入病人ID"
          clearable
          @keyup.enter="handleQuery"
          class="!w-170px"
        />
      </el-form-item>
      <el-form-item label="门诊号" prop="clinicNo">
        <el-input
          v-model="queryParams.clinicNo"
          placeholder="请输入门诊号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-170px"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCardNo">
        <el-input
          v-model="queryParams.idCardNo"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-220px"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="openid" prop="openid">
        <el-input
          v-model="queryParams.openid"
          placeholder="请输入微信openid"
          clearable
          @keyup.enter="handleQuery"
          class="!w-265px"
        />
      </el-form-item>
<!--      <el-form-item label="电子健康卡ID" prop="regDept">-->
<!--        <el-input-->
<!--          v-model="queryParams.ehealthCardId"-->
<!--          placeholder="请输入电子健康卡ID"-->
<!--          clearable-->
<!--          @keyup.enter="handleQuery"-->
<!--          class="!w-160px"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" border :show-overflow-tooltip="true" :data="list" :row-class-name="tableRowClassName" style="width: 100%;">
      <el-table-column label="病人姓名" align="center" prop="name" width="85" fixed="left"/>
      <el-table-column label="病人ID" align="center" prop="patientId" width="80" fixed="left" />
      <el-table-column label="门诊号" align="center" prop="clinicNo" width="100" fixed="left" />
      <el-table-column label="身份证号" align="center" prop="cardNo" width="160" />
      <el-table-column label="手机号码" align="center" prop="phone" width="110" />
      <el-table-column label="性别" align="center" prop="patientSex" width="60" />
      <el-table-column label="出生日期" align="center" prop="birthday" width="100" />
      <el-table-column label="民族" align="center" prop="nation" width="100"/>
      <el-table-column label="openid" align="center" prop="openid" min-width="240" :show-overflow-tooltip="true" />
      <el-table-column label="电子健康卡ID" align="center" prop="ehealthCardId" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="150" />
      <el-table-column label="更新时间" align="center" prop="lastUpdateTime" width="150" fixed="right"/>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import * as StaticsApi from '@/api/hosp/statics'
import {getPatientPage} from "@/api/hosp/statics";

defineOptions({ name: 'PatientOrder' })

const message = useMessage() // 消息弹窗

const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  searchTime: [],
  beginDate: '',
  endDate: '',
  patientName: '',
  patientId: '',
  clinicNo: '',
  idCardNo: '',
  phone: '',
  openid: '',
  ehealthCardId: ''
})
const queryFormRef = ref() // 搜索的表单

const tableRowClassName = ({row}) => {
  if (row.procedureStatus === 'success') {
    return 'my-table success-row'
  } else if (row.procedureStatus === 'fails') {
    return 'my-table fails-row'
  } else if (row.procedureStatus === 'refund') {
    return 'my-table refund-row'
  }
  return 'my-table'
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StaticsApi.getPatientPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}


/** 初始化 **/
onMounted(async () => {
  await getList()
})

</script>
<style scoped>
:deep(.el-table) {
  position: relative;
  overflow: hidden;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  width: 100%;
  max-width: 100%;
  font-size: 12px;
  color: #000000;
}
:deep(.refund-row) {
  background-color: #F3D39BFF !important;
}

:deep(.fails-row) {
  background-color: #D15B47 !important;
}

:deep(.success-row) {
  background-color: #36bc99 !important;
}
:deep(.my-table td) {
  padding: 5px 0 !important;
}

</style>
